package cj.web.portal.controllers;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseVoController {
	
	public final static String KEY_TOKEN_ = "6a04f2d6b4774052b1298903d4171730"; 
	
	public static final String IS_LOGIN ="IS_LOGIN";//是否需要
	
	public void removeCookie(HttpServletResponse response,String name){
		Cookie cookie = new Cookie(name, null);
		cookie.setPath("/");
		cookie.setMaxAge(0);
		response.addCookie(cookie); 
    }
	
    public void setCookie(HttpServletResponse response,String name,String value){
        Cookie cookie = new Cookie(name.trim(), value.trim());
        cookie.setPath("/");
        cookie.setMaxAge( 622080000 );
        response.addCookie(cookie);
    }
    
    public String getCookieValueByName(HttpServletRequest request,String name){
    	Cookie[] cookies = request.getCookies();
        if(null!=cookies && cookies.length > 0){
            for(Cookie cookie : cookies){
                if( name.equals(cookie.getName()) ){
                	return cookie.getValue();
                }
            }
        }
        
        return "";
    }
    
    public boolean isLogin(HttpServletRequest request){
    	String phone = getCookieValueByName(request,"phone");
    	if(!"".equals(phone)){
    		return true;
    	}
    	return false;
    }

}